package cn.edu.nju.ws.sview.rdf;


/**
 * RDF��Ԫ��
 * 
 * @author Gong Saisai
 * 
 */
public class RDFTriple {
	private Resource subject = null;
	private Resource predicate = null;
	private Resource object = null;
	private RDFDocument rdfDocument = null;

	/**
	 * 
	 * @param subject
	 *            ��RDF��Ԫ���subject
	 * @param predicate
	 *            ��RDF��Ԫ���predicate
	 * @param object
	 *            ��RDF��Ԫ���object
	 * @param rdfDocument
	 *            ��RDF��Ԫ��������RDF�ĵ�
	 */
	RDFTriple(Resource subject, Resource predicate, Resource object,
			RDFDocument rdfDocument) {
		this.subject = subject;
		this.predicate = predicate;
		this.object = object;
		this.rdfDocument = rdfDocument;
	}

	/**
	 * 
	 * @return ��RDF��Ԫ���subject
	 */
	public Resource getSubject() {
		return this.subject;
	}

	/**
	 * 
	 * @return ��RDF��Ԫ���predicate
	 */
	public Resource getPredicate() {
		return this.predicate;
	}

	/**
	 * 
	 * @return ��RDF��Ԫ���object
	 */
	public Resource getObject() {
		return this.object;
	}

	/**
	 * 
	 * @return ��RDF��Ԫ��������RDF�ĵ�
	 */
	public RDFDocument getRDFDocument() {
		return this.rdfDocument;
	}

	public boolean equals(Object rdfTriple) {
		if (rdfTriple instanceof RDFTriple) {
			RDFTriple rdfTripleO = (RDFTriple) rdfTriple;
			if (this.subject.equals(rdfTripleO.subject)
					&& this.predicate.equals(rdfTripleO.predicate)
					&& this.object.equals(rdfTripleO.object)
					&& this.rdfDocument.equals(rdfTripleO.rdfDocument)) {
				return true;
			}
		}
		return false;
	}

	public int hashCode() {
		return this.subject.hashCode() + this.predicate.hashCode()
				+ this.object.hashCode() + this.rdfDocument.hashCode();
	}

	public String toString() {
		return this.subject.toString() + " " + this.predicate.toString() + " "
				+ this.object.toString() + " IN " + this.rdfDocument.toString();
	}
}